-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add GenericDocument<>::Swap #376
Conversation
I suggest not to include |
Why not using lowercase "swap" for the method name? In that case it could work hand in hand with std::swap() and std::swap(doc1, doc2) would automatically pick up the optimized implementation; otherwise std::swap() would do the unoptimized create-copy-temp-from-b, copy-a-to-b, copy-temp-to-a thing... |
@miloyip Ok, I'll try to have a look. @Kosta-Github Providing a lower-case |
Yeah, I am aware of the inconsistency but still think that easy/efficient interop with the STL is also worth to be considered. Users most probably will not provide their own |
This avoids the dependency on the <algorithm> header, as suggested by @miloyip in Tencent#376.
@miloyip: I have now added a new helper function @Kosta-Github: On my platform, We could add an "inline friend" function to // add to GenericValue, GenericDocument (analogously)
friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT
{ a.Swap(b); }
// enables common pattern:
using std::swap;
swap(v1, v2); // calls GenericValue's friend through argument-dependent lookup @miloyip, what do you think? |
@pah I think both changes are OK for me. |
I've just added the two free-standing friend |
add GenericDocument<>::Swap with std::swap() support
Brilliant~ |
See #368.